package com.hzhr.iot.device.dao;

import com.hzhr.iot.device.dao.mapper.custom.DeviceMaintenanceCardItemEntityCustomMapper;
import com.hzhr.iot.device.dao.mapper.generator.DeviceMaintenanceCardItemEntityMapper;
import com.hzhr.iot.device.entity.DeviceMaintenanceCardItemEntity;
import com.hzhr.iot.device.entity.ext.DeviceMaintenanceCardItemEntityExt;
import com.hzhr.iot.device.queryModel.custom.DeviceMaintenanceCardItemCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Repository
public class DeviceMaintenanceCardItemDao {
    @Autowired
    DeviceMaintenanceCardItemEntityMapper deviceMaintenanceCardItemEntityMapper;

    @Autowired
    DeviceMaintenanceCardItemEntityCustomMapper deviceMaintenanceCardItemEntityCustomMapper;

    public int insert(DeviceMaintenanceCardItemEntity record) {
        if (record == null) return 0;
        int changeCount = deviceMaintenanceCardItemEntityMapper.insert(record);
        return changeCount;
    }

    public int delete(DeviceMaintenanceCardItemCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = deviceMaintenanceCardItemEntityCustomMapper.delete(queryModel);
        return changeCount;
    }

    public int update(DeviceMaintenanceCardItemEntity record) {
        if (record == null) return 0;
        int changeCount = deviceMaintenanceCardItemEntityMapper.updateByPrimaryKey(record);
        return changeCount;
    }

    public int updateProps(DeviceMaintenanceCardItemCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = deviceMaintenanceCardItemEntityCustomMapper.updateProps(queryModel);
        return changeCount;
    }

    public DeviceMaintenanceCardItemEntity selectEntity(DeviceMaintenanceCardItemCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<DeviceMaintenanceCardItemEntityExt> extList = deviceMaintenanceCardItemEntityCustomMapper.selectExt(queryModel);
        return extList.get(0);
    }


    public List<DeviceMaintenanceCardItemEntity> selectEntityList(DeviceMaintenanceCardItemCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<DeviceMaintenanceCardItemEntityExt> extList = deviceMaintenanceCardItemEntityCustomMapper.selectExt(queryModel);
        if (extList == null) return null;
        List<DeviceMaintenanceCardItemEntity> entityList = new ArrayList<>();
        for (DeviceMaintenanceCardItemEntity ext : extList) {
            entityList.add(ext);
        }
        return entityList;
    }

//    private Date maintenanceTime;
    public List<DeviceMaintenanceCardItemEntity> selectEntityListAndOrderByTime(DeviceMaintenanceCardItemCustomQueryModel queryModel, Date maintenanceTime) {
        if (queryModel == null) return null;
        List<DeviceMaintenanceCardItemEntityExt> extList = deviceMaintenanceCardItemEntityCustomMapper.selectExt(queryModel);
        if (extList == null) return null;
        List<DeviceMaintenanceCardItemEntity> entityList = new ArrayList<>();
        for (DeviceMaintenanceCardItemEntity ext : extList) {
            entityList.add(ext);
        }
        return entityList;
    }

    public DeviceMaintenanceCardItemEntityExt selectExt(DeviceMaintenanceCardItemCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<DeviceMaintenanceCardItemEntityExt> extList = deviceMaintenanceCardItemEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }

    public DeviceMaintenanceCardItemEntityExt selectExt1(DeviceMaintenanceCardItemCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<DeviceMaintenanceCardItemEntityExt> extList = deviceMaintenanceCardItemEntityCustomMapper.selectExt1(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }

    public List<DeviceMaintenanceCardItemEntityExt> selectExtList(DeviceMaintenanceCardItemCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<DeviceMaintenanceCardItemEntityExt> extList = deviceMaintenanceCardItemEntityCustomMapper.selectExt(queryModel);
        return extList;
    }


    // 自定义or查询
    public List<DeviceMaintenanceCardItemEntityExt> selectExtList1(DeviceMaintenanceCardItemCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<DeviceMaintenanceCardItemEntityExt> extList = deviceMaintenanceCardItemEntityCustomMapper.selectExt1(queryModel);
        return extList;
    }

    public int selectCount(DeviceMaintenanceCardItemCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int count = deviceMaintenanceCardItemEntityCustomMapper.selectCount(queryModel);
        return count;
    }







}
